home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / DELTREE2.BAT < prev    next >
DOS Batch File  |  1993-06-24  |  2KB  |  61 lines

  1. @echo off
  2. REM DelTree2 - Delete a directory, including all files and subdirectories.  This
  3. REM            is quicker than DelTree1 because it works one directory at a time.
  4. if "%1"=="" GOTO SHOW_HOW
  5.  
  6. :This is a dangerious function, so make sure they really want it
  7.    ECHO THIS WILL DELETE ALL FILES AND DIRECTORIES UNDER %1
  8.    ECHO %1 MUST BE A VALID DIRECTORY AND YOU NEED MSDOS 5
  9.    CEnvi GetUKey.cmm ARE YOU SURE YOU WANT TO DO THIS? (Y/N)    yn
  10.    if N==%UKEY% GOTO FINI
  11.  
  12. :Check that it is a valid file name
  13.    CEnvi ValidDir.bat %1 COMPLAIN
  14.    if ERRORLEVEL 1 GOTO FINI
  15.  
  16. :Unset attributes so that all files can be deleted
  17.    attrib -H -S -R %1\*.* /s > NUL
  18.  
  19. :Delete each directory
  20.    dir %1 /Ad /f /s /On | cenvi #include '%0,bat,,GOTO END_SOURCE,:END_SOURCE'
  21.  
  22.    GOTO END_SOURCE
  23.  
  24.       // Create list of all the sub-directories
  25.       DirCount = 0
  26.       while ( NULL != (DirName = gets()) ) {
  27.          if ( DirName[strlen(DirName)-1] != '.' )  // dot and double-dot aren't sub-directories
  28.             strcpy(DirList[DirCount++],DirName)
  29.       }
  30.       // for each directory in that list delete all the files and then the directory.
  31.       // Do this in reverse order because it's in reverse order so we won't
  32.       // try to delete a directory while it still has subdirectories.
  33.       for ( i = DirCount; i != 0; i-- ) {
  34.          DirName = DirList[i-1]
  35.          sprintf(Command,"echo Y | del %s\\*.* > NUL",DirName)
  36.          printf("DEL %s\\*.*\n",DirName)
  37.          system(Command)
  38.          sprintf(Command,"RMDIR %s",DirName)
  39.          printf("%s\n",Command)
  40.          system(Command)
  41.       }
  42.  
  43.    :END_SOURCE
  44.  
  45. :Finally, delete the directory itself
  46.    ECHO DEL %1\*.*
  47.    ECHO Y | DEL %1\*.*
  48.    ECHO RMDIR %1
  49.    RMDIR %1 > NUL
  50. GOTO FINI
  51.  
  52.  
  53. :SHOW_HOW
  54. ECHO  
  55. ECHO DelTree2.bat - Delete this directory and all files and subdirectories within it.
  56. ECHO  
  57. GOTO FINI
  58.  
  59. :FINI
  60. set UKEY=
  61.